package com.qf.springmvc.controller;

import com.qf.springmvc.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;


@Controller
@RequestMapping("data")
@SessionAttributes({"name","age"})

public class DataController {

    @RequestMapping("test1")
    public String test1(HttpServletRequest request, HttpSession session) {

        request.setAttribute("name", "EEE");
        request.setAttribute("age", 18);

        session.setAttribute("date", "2022");
        return "welcome";
    }


    @RequestMapping("test2")
    public String test2(Model model) {

        model.addAttribute("name", "CC");
        model.addAttribute("age", 17);

        model.addAttribute("BB");
        User user = new User();
        user.setName("DD");
        user.setId(11);
        model.addAttribute(user);
        return "welcome";
    }

    @RequestMapping("test3")
    public ModelAndView test3() {
        ModelAndView modelAndView = new ModelAndView("welcome");
        modelAndView.addObject("name","AA");
        return modelAndView;
    }
}
